from django.shortcuts import render,redirect
from django.contrib.auth import authenticate,login,logout
from account.models import  MyUser

# Create your views here.

def sign_in(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('passwd')
        userObjects = authenticate(username=username,password=password)
        if userObjects is not None:
            if userObjects.is_active:
                login(request,userObjects)
                return redirect('dashboard')
        return render(request,'sign-in.html',{'error':'user or password error please try again!'})
    return render(request,'sign-in.html')


def sign_out(request):
    logout(request)
    return redirect('login')
